package org.gtugs.omsk.funnycats.scenes;

import org.cocos2d.actions.instant.CCCallFunc;
import org.cocos2d.actions.interval.CCDelayTime;
import org.cocos2d.actions.interval.CCSequence;
import org.cocos2d.layers.CCColorLayer;
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCLabel;
import org.cocos2d.types.CGSize;
import org.cocos2d.types.ccColor3B;
import org.cocos2d.types.ccColor4B;

import android.view.MotionEvent;

public class GameOverScene extends CCColorLayer{
	
	public static CCScene scene(String message)
    {
        CCScene scene = CCScene.node();
        GameOverScene layer = new GameOverScene(ccColor4B.ccc4(255, 255, 255, 255));
 
        layer.getLabel().setString(message);
 
        scene.addChild(layer);
 
        return scene;
    }
	
	public GameOverScene(ccColor4B color) {
		super(color);
		
		this.setIsTouchEnabled(true);
		
		CGSize windowSize = CCDirector.sharedDirector().winSize();
		
		mMessageLabel = CCLabel.makeLabel("Initial string", "DroidSans", 32);
		mMessageLabel.setColor(ccColor3B.ccBLACK);
		mMessageLabel.setPosition(windowSize.width / 2.0f, windowSize.height / 2.0f);
		
		addChild(mMessageLabel);
		
		this.runAction(CCSequence.actions(CCDelayTime.action(3.0f), CCCallFunc.action(this,	"exitGameOver")));
	}
	
	private CCLabel getLabel(){
		return mMessageLabel;
	}
	
	private void exitGameOver(){
		CCDirector.sharedDirector().replaceScene(GameScene.scene());
	}
	
	@Override
	public boolean ccTouchesEnded(MotionEvent event) {
		exitGameOver();
		return true;
	}
	
	private CCLabel mMessageLabel;
}
